package com.mdd.maduoduo.data.reposipory;


import com.mdd.maduoduo.MyApplication;
import com.mdd.maduoduo.constants.CommonConstants;
import com.mdd.maduoduo.data.network.LoginService;
import com.mdd.maduoduo.domain.repository.LoginRepository;
import com.mdd.maduoduo.entity.BannerEntity;
import com.mdd.maduoduo.entity.CheckVersionEntity;
import com.mdd.maduoduo.entity.LoginEntity;
import com.mdd.maduoduo.entity.MaxConfigEntity;
import com.mdd.maduoduo.entity.MaxDataEntity;
import com.mdd.maduoduo.entity.QueryListEntity;
import com.mdd.maduoduo.entity.Response;
import com.mdd.maduoduo.entity.ShareCodeEntity;
import com.mdd.maduoduo.entity.StationEntity;
import com.mdd.maduoduo.entity.UserEntity;
import com.mdd.maduoduo.utils.SpUtils;

import java.util.HashMap;

import javax.inject.Inject;

import io.reactivex.Observable;
import retrofit2.Retrofit;

public class LoginRepositoryImpl implements LoginRepository {

    private LoginService mService;

    @Inject
    LoginRepositoryImpl(Retrofit retrofit) {
        mService = retrofit.create(LoginService.class);
    }


    @Override
    public Observable<Response<LoginEntity>> login(String url) {
        return mService.login(url);
    }

    @Override
    public Observable<UserEntity> getUser() {
        return mService.getUser(getAccessToken());
    }

    @Override
    public Observable<MaxConfigEntity> getMaxConfig() {
        return mService.getMaxConfig(getAccessToken());
    }

    @Override
    public Observable<Response> setSwitch(HashMap<String, Object> map) {
        return mService.setSwitch(getAccessToken(),map);
    }

    @Override
    public Observable<MaxDataEntity> getMaxData() {
        return mService.getMaxData(getAccessToken());
    }

    @Override
    public Observable<Response> exchange(HashMap<String, Object> map) {
        return mService.exchange(getAccessToken(),map);
    }

    @Override
    public Observable<Response> logout() {
        return mService.logout(getAccessToken());
    }

    @Override
    public Observable<Response> addShareCode(HashMap<String, Object> map) {
        return mService.addShareCode(getAccessToken(),map);
    }

    @Override
    public Observable<ShareCodeEntity> getShareCode() {
        return mService.getShareCode(getAccessToken());
    }

    @Override
    public Observable<Response> deleteShareCode(String pickupSharedCode) {
        return mService.deleteShareCode(getAccessToken(),pickupSharedCode);
    }

    @Override
    public Observable<Response> updateTime(HashMap<String, Object> map) {
        return mService.updateTime(getAccessToken(),map);
    }

    @Override
    public Observable<Response> addMsg(HashMap<String, Object> map) {
        return mService.addMsg(getAccessToken(),map);
    }

    @Override
    public Observable<QueryListEntity> queryList(HashMap<String, Object> map) {
        return mService.queryList(getAccessToken(),map);
    }

    @Override
    public Observable<StationEntity> getStation(int pickupStatus) {
        return mService.getStation(getAccessToken(),pickupStatus);
    }

    @Override
    public Observable<Response> updateCodeStatus(HashMap<String, Object> map) {
        return mService.updateCodeStatus(getAccessToken(),map);
    }

    @Override
    public Observable<Response> deleteCode(HashMap<String, Object> map) {
        return mService.deleteCode(getAccessToken(),map);
    }

    @Override
    public Observable<BannerEntity> getBannerList(String pTag) {
        return mService.getBannerList(getAccessToken(),pTag);
    }

    @Override
    public Observable<CheckVersionEntity> checkVersion(HashMap<String, Object> map) {
        return mService.checkVersion(getAccessToken(),map);
    }


    private String getAccessToken() {
        return "Bearer "+ SpUtils.get(MyApplication.getContext(), CommonConstants.TOKEN);
    }
}
